﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameAndNode_updated
{
    class Drawer
    {
       
        public void FrameDrawing(char ch, GameFiled filed, Frame frame)
        {
            int yPosition = filed.StartY-1;
            int xPosition = filed.StartX-1;
            char[,] firstFrame = new char[frame.Height, frame.Width];
            for (int i = 0; i < firstFrame.GetLength(0); i++)
            {
                for (int j = 0; j < firstFrame.GetLength(1); j++)
                {
                    if (( i == frame.Height - 1) || j == 0 || j == frame.Width - 1)
                    {
                        firstFrame[i, j] = ch;
                    }
                    else
                    {
                        firstFrame[i, j] = ' ';
                    }
                }
            }
            for (int i = 0; i < firstFrame.GetLength(0); i++)
            {
                Console.SetCursorPosition(xPosition, yPosition++);
                for (int j = 0; j < firstFrame.GetLength(1); j++)
                {
                    Console.Write(firstFrame[i, j]);
                }
            }
        }

        public void DrawGameNode(GameNode node, ConsoleColor color, char symbol)
        {
            Console.ForegroundColor = color;
            Console.SetCursorPosition(node.XNode, node.YNode);
            Console.WriteLine(symbol);
            //System.Threading.Thread.Sleep(600);
            Console.ForegroundColor = ConsoleColor.White;
        }

        public void ClearGameNode(GameNode node)
        {
            Console.SetCursorPosition(node.XNode, node.YNode);
            Console.WriteLine(' ');
        }

        public void DrawNode(GameNode node, ConsoleColor color, char symbol)
        {
            DrawGameNode(node, color, symbol);
            ClearGameNode(node);
        }

        public void ScoreInfo(GameFiled field, int ateScore, int currentSpeed, int numOfSpeed)
        {
            int x_coord = field.StartX + field.Width + 10;
            int y_coord = field.StartY+1;
            Console.SetCursorPosition(x_coord, y_coord);
            Console.WriteLine("Count of targets:\tSpeed:\t\tPause - P");
            y_coord++;
            Console.SetCursorPosition(x_coord, y_coord);
            Console.WriteLine("\t{0}\t\t{1}: {2}", ateScore, numOfSpeed, currentSpeed);
        }

        public string GameOverInfo(GameFiled field)
        {
            int x_coord = field.StartX + field.Width + 10;
            int y_coord = field.StartY + 3;
            Console.SetCursorPosition(x_coord, y_coord);
            Console.WriteLine("Game Over");
            Console.SetCursorPosition(x_coord, ++y_coord);
            Console.WriteLine("Do you want to try again? (Y/N).");
            Console.SetCursorPosition(x_coord, ++y_coord);           
            return Console.ReadLine().ToUpper();
        }

        public void ClearGameInfo(GameFiled field)
        {
            int x_coord = field.StartX + field.Width + 10;
            int y_coord = field.StartY + 3;
            Console.SetCursorPosition(x_coord, y_coord);
            Console.WriteLine("                                                                                       ");
            Console.SetCursorPosition(x_coord, ++y_coord);
            Console.WriteLine("                                                                                       ");
            Console.SetCursorPosition(x_coord, ++y_coord);
            Console.WriteLine("                                                                                       ");
            Console.SetCursorPosition(x_coord, ++y_coord);
        }

    }
}
